<template>
  <div class="nvanp" @click="gettitl">
    <loading v-if="isLoading"></loading>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">重磅推荐</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="item in book_list[0]">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
      <div class="booklist">
        <ul>
          <li v-for="item in book_list[1]">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">现代言情</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[7]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img  v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">古代言情</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[8]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">最红新书</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[4]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">完本精选</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[6]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed butom">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">畅销榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="(item, i) in book_list[5]" v-if="i < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <b :class="'rank-' + (i + 1)"></b>
              <div class="book-1">
                <img v-load="item.cover" :src="error"  alt="" />
              </div>
              <div class="text-tb">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <!-- <div class="butom"></div> -->
  </div>
</template>
<script>
import error from "@/assets/noimg.png";
import { recommendFunc, reFunc } from "@/request/index";
import Loading from "@/components/loading/indexlist.vue";
export default {
  directives:{
    load(el,options){
      let img = new Image()
      img.src = options.value;
      img.onload=()=>{
        el.src =options.value
      }
    }
  },
  data() {
    return {
      error,
      book_list: [],
      url: "",
      title: "",
      isLoading: true,
    };
  },
  components: {
    Loading
  },
  methods: {
    async csfe() {
      await recommendFunc().then((res) => {
        // console.log(res.data);
        let { navi } = res.data;
        // console.log(navi);
        this.url = navi[3].url;
        reFunc(navi[3].url).then((lis) => {
          // console.log(lis);
          let { list } = lis.data;
          // console.log(list);
          // 整合数据
          // let{list}=list
          this.book_list = list.map((item) => {
            // console.log(item);
            // console.log(list);
            return item.list;
          });
          this.book_list.splice(0, 1);
          // console.log(this.book_list);
        }).catch(err => {
          console.log("请求失败...");
        });
        this.isLoading = false;
      }).catch(err => {
          console.log("请求失败...");
        });
    },
    gettitl(e) {
      // console.log(e.target.className);
      if (e.target.textContent === "更多") {
        // console.log(e.target.parentNode.firstChild.textContent);
        this.title = e.target.parentNode.firstChild.textContent;
      }
      // console.log(this.title)
      let titles= this.title
      let urls = this.url
      this.$router.push(`/modo?list_title=${titles}&url=${urls}`);
      
    },
  },
  created() {
    this.csfe();
  },
};
</script>
<style lang="scss">
@import url(../../static/css/reset.css);
.butom {
  box-sizing: border-box;
  li {
    position: relative;
    b {
      position: absolute;
      top: -2px;
      left: 7.8px;
      right: 0;
      width: 86%;
      height: 22px;
      background: 0 0 no-repeat;
      background-size: 100% auto;
      z-index: 9;
      &.rank-1 {
        background-image: url(../../static/imgs/icon_01.png);
      }
      &.rank-2 {
        background-image: url(../../static/imgs/icon_02.png);
      }
      &.rank-3 {
        background-image: url(../../static/imgs/icon_03.png);
      }
    }
    h4 {
      font-size: 15px;
      line-height: 19px;
      height: 38px;
      max-height: 38px;
      margin: 10px 0 5px;
      overflow: hidden;
      color: #222;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    p {
      color: #888;
      line-height: 15px;
      height: 15px;
      font-size: 12px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
.nvanp {
  margin: auto 5%;
  margin-top: 3px;
  .hed {
    width: 100%;
    h3 {
      height: 28px;
      line-height: 28px;
      margin-bottom: 16px;
      font-weight: bold;
      .gradient {
        float: left;
        display: inline-block;
        font-size: 20px;
        color: #1a1a1a;
      }
      .more {
        float: right;
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        box-sizing: border-box;
        border: 1px solid #f0f0f0;
        border-radius: 28px;
      }
    }
    .bookbox {
      width: 100%;
      // background: black;
      ul {
        display: flex;
        li {
          width: 34%;
          [class^="book"] {
            margin: 9px;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            color: #333;
            outline: none;
            padding-left: 10%;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
             text-overflow: ellipsis;
              overflow: hidden;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            [class^="name"] {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
            }
          }
        }
      }
    }
    .booklist {
      margin-top: 20px;
      width: 100%;
      // background: black;
      ul {
        li {
          display: flex;
          width: 100%;
          [class^="book"] {
            float: left;
            width: 93px;
            margin: 9px;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            padding-top: 10px;
            color: #333;
            outline: none;
            padding-left: 10px;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
            }
            [class^="name"] {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
              margin-bottom: 5px;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            [class^="p"] {
              color: #888;
              line-height: 18px;
              height: 36px;
              -webkit-line-clamp: 2;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            [class^="tag"] {
              padding-top: 13px;
              span {
                display: inline-block;
                margin-right: 2px;
                padding: 0 12px;
                height: 22px;
                line-height: 22px;
                font-size: 12px;
                color: #999;
                background-image: linear-gradient(
                  3deg,
                  #f9f9f9 0,
                  #f0f0f0 100%
                );
                border-radius: 22px;
              }
            }
          }
        }
      }
    }
  }
}
</style>
  